package com.zoshine.zzg;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4;
import com.alibaba.fastjson.support.spring.FastJsonpResponseBodyAdvice;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;

/**
 * 应用启动入口
 *
 * @author 贾俊峰
 * @time 2017/6/13 10:53
 */
@SpringBootApplication
@MapperScan("com.zoshine.zzg.dao")
@EnableScheduling
public class ZZGApp {
    @Bean
    public FastJsonpResponseBodyAdvice fastJsonpResponseBodyAdvice() {
        return new FastJsonpResponseBodyAdvice("callback", "jsonp");
    }
    @Bean
    public HttpMessageConverters fastJsonHttpMessageConverters() {
        FastJsonHttpMessageConverter4 fastJsonHttpMessageConverter4 = new FastJsonHttpMessageConverter4();

        FastJsonConfig fastJsonConfig = new FastJsonConfig();
        fastJsonConfig.setCharset(Charset.forName("UTF-8"));
        fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
        fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue, SerializerFeature.DisableCircularReferenceDetect, SerializerFeature.WriteNonStringValueAsString);
        fastJsonHttpMessageConverter4.setFastJsonConfig(fastJsonConfig);

        List<MediaType> mediaTypeList = new ArrayList<>();
        mediaTypeList.add(MediaType.APPLICATION_JSON);

        fastJsonHttpMessageConverter4.setSupportedMediaTypes(mediaTypeList);
        return new HttpMessageConverters(fastJsonHttpMessageConverter4);
    }

    public static void main(String[] args) {
        SpringApplication.run(ZZGApp.class, args);
    }
}
